package com.zy.design.demo.creational;

/**
 * 建造者模式
 * 特点：分步构建复杂对象。
 */
class Meal {
    private String food, drink;

    static class Builder {
        private String food, drink;

        public Builder setFood(String food) { this.food = food; return this; }
        public Builder setDrink(String drink) { this.drink = drink; return this; }
        public Meal build() { return new Meal(this); }
    }

    private Meal(Builder builder) {
        this.food = builder.food;
        this.drink = builder.drink;
    }

    public void display() {
        System.out.println("套餐: 食物=" + food + ", 饮料=" + drink);
    }
}

class Main1 {
    public static void main(String[] args) {
        Meal meal = new Meal.Builder().setFood("牛排").setDrink("红酒").build();
        meal.display();

        Meal newMeal = new Meal.Builder().setFood("狗肉").setDrink("羊汤").build();
        newMeal.display();
    }
}
